// $ANTLR 3.4 C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g 2012-11-07 16:27:24

  package PL.practica8;
  import java.util.Hashtable;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

@SuppressWarnings({"all", "warnings", "unchecked"})
public class ExpresionesParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "ABRIRPARENTESIS", "ASIGNACION", "ASTERISCO", "BLANCO", "CERRARPARENTESIS", "COMENTARIO", "DIGITO", "ID", "LETRA", "MAS", "MENOS", "NUEVA_LINEA", "NUMERO", "SEPARADOR", "SLASH"
    };

    public static final int EOF=-1;
    public static final int ABRIRPARENTESIS=4;
    public static final int ASIGNACION=5;
    public static final int ASTERISCO=6;
    public static final int BLANCO=7;
    public static final int CERRARPARENTESIS=8;
    public static final int COMENTARIO=9;
    public static final int DIGITO=10;
    public static final int ID=11;
    public static final int LETRA=12;
    public static final int MAS=13;
    public static final int MENOS=14;
    public static final int NUEVA_LINEA=15;
    public static final int NUMERO=16;
    public static final int SEPARADOR=17;
    public static final int SLASH=18;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public ExpresionesParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public ExpresionesParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

    public String[] getTokenNames() { return ExpresionesParser.tokenNames; }
    public String getGrammarFileName() { return "C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g"; }


      Hashtable<String, Integer> variables = new Hashtable<String, Integer>();
      ArrayList <RecognitionException> errores = new ArrayList<RecognitionException>();

    	public boolean listaVacia (){
    	    if (errores.isEmpty()){
    	      return true;
    	    }else
    	      return false;
    	}
    	
    	public ArrayList getListaErrores(){return errores;}
    	
    	
    	@Override
    	public void reportError (RecognitionException e){
    	  System.err.println (getErrorMessage(e, getTokenNames()));
    	  errores.add(e);
    }




    // $ANTLR start "entrada"
    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:38:1: entrada : ( asignacion | instruccion )* ;
    public final void entrada() throws RecognitionException {
        try {
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:38:8: ( ( asignacion | instruccion )* )
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:38:10: ( asignacion | instruccion )*
            {
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:38:10: ( asignacion | instruccion )*
            loop1:
            do {
                int alt1=3;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==ID) ) {
                    int LA1_2 = input.LA(2);

                    if ( (LA1_2==ASIGNACION) ) {
                        alt1=1;
                    }
                    else if ( (LA1_2==ASTERISCO||(LA1_2 >= MAS && LA1_2 <= MENOS)||(LA1_2 >= SEPARADOR && LA1_2 <= SLASH)) ) {
                        alt1=2;
                    }


                }
                else if ( (LA1_0==ABRIRPARENTESIS||LA1_0==NUMERO) ) {
                    alt1=2;
                }


                switch (alt1) {
            	case 1 :
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:38:11: asignacion
            	    {
            	    pushFollow(FOLLOW_asignacion_in_entrada50);
            	    asignacion();

            	    state._fsp--;


            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:38:22: instruccion
            	    {
            	    pushFollow(FOLLOW_instruccion_in_entrada52);
            	    instruccion();

            	    state._fsp--;


            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "entrada"



    // $ANTLR start "asignacion"
    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:40:4: asignacion : id= ID ASIGNACION e= expr SEPARADOR ;
    public final void asignacion() throws RecognitionException {
        Token id=null;
        int e =0;


        try {
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:40:15: (id= ID ASIGNACION e= expr SEPARADOR )
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:40:17: id= ID ASIGNACION e= expr SEPARADOR
            {
            id=(Token)match(input,ID,FOLLOW_ID_in_asignacion67); 

            match(input,ASIGNACION,FOLLOW_ASIGNACION_in_asignacion69); 

            pushFollow(FOLLOW_expr_in_asignacion73);
            e=expr();

            state._fsp--;


            match(input,SEPARADOR,FOLLOW_SEPARADOR_in_asignacion75); 


                System.out.println("Asignacion (" + id.getText() + ") => " + e);
                  variables.put(id.getText(), new Integer(e));
                  
              

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "asignacion"



    // $ANTLR start "instruccion"
    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:47:4: instruccion : e= expr SEPARADOR ;
    public final void instruccion() throws RecognitionException {
        int e =0;


        try {
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:47:16: (e= expr SEPARADOR )
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:47:18: e= expr SEPARADOR
            {
            pushFollow(FOLLOW_expr_in_instruccion91);
            e=expr();

            state._fsp--;


            match(input,SEPARADOR,FOLLOW_SEPARADOR_in_instruccion93); 


                System.out.println("Expresion => " + e);
              

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return ;
    }
    // $ANTLR end "instruccion"



    // $ANTLR start "expr"
    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:51:2: expr returns [int res=0] : e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e2= exp_mult ) )* ;
    public final int expr() throws RecognitionException {
        int res = 0;


        int e1 =0;

        int e2 =0;


        try {
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:51:26: (e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e2= exp_mult ) )* )
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:51:28: e1= exp_mult ( ( MAS e2= exp_mult ) | ( MENOS e2= exp_mult ) )*
            {
            pushFollow(FOLLOW_exp_mult_in_expr112);
            e1=exp_mult();

            state._fsp--;


             res = e1; 

            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:51:54: ( ( MAS e2= exp_mult ) | ( MENOS e2= exp_mult ) )*
            loop2:
            do {
                int alt2=3;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==MAS) ) {
                    alt2=1;
                }
                else if ( (LA2_0==MENOS) ) {
                    alt2=2;
                }


                switch (alt2) {
            	case 1 :
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:51:55: ( MAS e2= exp_mult )
            	    {
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:51:55: ( MAS e2= exp_mult )
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:51:56: MAS e2= exp_mult
            	    {
            	    match(input,MAS,FOLLOW_MAS_in_expr118); 

            	    pushFollow(FOLLOW_exp_mult_in_expr122);
            	    e2=exp_mult();

            	    state._fsp--;


            	    }


            	     res = res + e2; 

            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:52:4: ( MENOS e2= exp_mult )
            	    {
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:52:4: ( MENOS e2= exp_mult )
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:52:5: MENOS e2= exp_mult
            	    {
            	    match(input,MENOS,FOLLOW_MENOS_in_expr132); 

            	    pushFollow(FOLLOW_exp_mult_in_expr136);
            	    e2=exp_mult();

            	    state._fsp--;


            	    }


            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            res=e1+e2;

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "expr"



    // $ANTLR start "exp_mult"
    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:56:2: exp_mult returns [int res = 0] : e1= exp_base ( ( ASTERISCO e2= exp_base ) | ( SLASH e2= exp_base ) )* ;
    public final int exp_mult() throws RecognitionException {
        int res =  0;


        int e1 =0;

        int e2 =0;


        try {
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:56:34: (e1= exp_base ( ( ASTERISCO e2= exp_base ) | ( SLASH e2= exp_base ) )* )
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:56:37: e1= exp_base ( ( ASTERISCO e2= exp_base ) | ( SLASH e2= exp_base ) )*
            {
            pushFollow(FOLLOW_exp_base_in_exp_mult175);
            e1=exp_base();

            state._fsp--;


            res=e1;

            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:56:59: ( ( ASTERISCO e2= exp_base ) | ( SLASH e2= exp_base ) )*
            loop3:
            do {
                int alt3=3;
                int LA3_0 = input.LA(1);

                if ( (LA3_0==ASTERISCO) ) {
                    alt3=1;
                }
                else if ( (LA3_0==SLASH) ) {
                    alt3=2;
                }


                switch (alt3) {
            	case 1 :
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:56:60: ( ASTERISCO e2= exp_base )
            	    {
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:56:60: ( ASTERISCO e2= exp_base )
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:56:61: ASTERISCO e2= exp_base
            	    {
            	    match(input,ASTERISCO,FOLLOW_ASTERISCO_in_exp_mult181); 

            	    pushFollow(FOLLOW_exp_base_in_exp_mult185);
            	    e2=exp_base();

            	    state._fsp--;


            	     res = res * e2; 

            	    }


            	    }
            	    break;
            	case 2 :
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:57:4: ( SLASH e2= exp_base )
            	    {
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:57:4: ( SLASH e2= exp_base )
            	    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:57:5: SLASH e2= exp_base
            	    {
            	    match(input,SLASH,FOLLOW_SLASH_in_exp_mult196); 

            	    pushFollow(FOLLOW_exp_base_in_exp_mult200);
            	    e2=exp_base();

            	    state._fsp--;


            	     res = res / e2; 

            	    }


            	    }
            	    break;

            	default :
            	    break loop3;
                }
            } while (true);


            }

        }
        catch (ArithmeticException ae) {
            System.err.println("Error aritmetico");
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "exp_mult"



    // $ANTLR start "exp_base"
    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:60:2: exp_base returns [int res = 0] : (n= NUMERO | ABRIRPARENTESIS e= expr CERRARPARENTESIS |id= ID );
    public final int exp_base() throws RecognitionException {
        int res =  0;


        Token n=null;
        Token id=null;
        int e =0;


        try {
            // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:60:32: (n= NUMERO | ABRIRPARENTESIS e= expr CERRARPARENTESIS |id= ID )
            int alt4=3;
            switch ( input.LA(1) ) {
            case NUMERO:
                {
                alt4=1;
                }
                break;
            case ABRIRPARENTESIS:
                {
                alt4=2;
                }
                break;
            case ID:
                {
                alt4=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 4, 0, input);

                throw nvae;

            }

            switch (alt4) {
                case 1 :
                    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:60:35: n= NUMERO
                    {
                    n=(Token)match(input,NUMERO,FOLLOW_NUMERO_in_exp_base234); 

                     res = Integer.parseInt(n.getText()); 

                    }
                    break;
                case 2 :
                    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:61:5: ABRIRPARENTESIS e= expr CERRARPARENTESIS
                    {
                    match(input,ABRIRPARENTESIS,FOLLOW_ABRIRPARENTESIS_in_exp_base242); 

                    pushFollow(FOLLOW_expr_in_exp_base246);
                    e=expr();

                    state._fsp--;


                    match(input,CERRARPARENTESIS,FOLLOW_CERRARPARENTESIS_in_exp_base248); 

                     res = e; 

                    }
                    break;
                case 3 :
                    // C:\\Users\\Jose\\workspace\\practica8\\src\\main\\java\\PL\\practica8\\ExpresionesParser.g:62:5: id= ID
                    {
                    id=(Token)match(input,ID,FOLLOW_ID_in_exp_base260); 

                     res = variables.get(id.getText()); 

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }

        finally {
        	// do for sure before leaving
        }
        return res;
    }
    // $ANTLR end "exp_base"

    // Delegated rules


 

    public static final BitSet FOLLOW_asignacion_in_entrada50 = new BitSet(new long[]{0x0000000000010812L});
    public static final BitSet FOLLOW_instruccion_in_entrada52 = new BitSet(new long[]{0x0000000000010812L});
    public static final BitSet FOLLOW_ID_in_asignacion67 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_ASIGNACION_in_asignacion69 = new BitSet(new long[]{0x0000000000010810L});
    public static final BitSet FOLLOW_expr_in_asignacion73 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_SEPARADOR_in_asignacion75 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_expr_in_instruccion91 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_SEPARADOR_in_instruccion93 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_exp_mult_in_expr112 = new BitSet(new long[]{0x0000000000006002L});
    public static final BitSet FOLLOW_MAS_in_expr118 = new BitSet(new long[]{0x0000000000010810L});
    public static final BitSet FOLLOW_exp_mult_in_expr122 = new BitSet(new long[]{0x0000000000006002L});
    public static final BitSet FOLLOW_MENOS_in_expr132 = new BitSet(new long[]{0x0000000000010810L});
    public static final BitSet FOLLOW_exp_mult_in_expr136 = new BitSet(new long[]{0x0000000000006002L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult175 = new BitSet(new long[]{0x0000000000040042L});
    public static final BitSet FOLLOW_ASTERISCO_in_exp_mult181 = new BitSet(new long[]{0x0000000000010810L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult185 = new BitSet(new long[]{0x0000000000040042L});
    public static final BitSet FOLLOW_SLASH_in_exp_mult196 = new BitSet(new long[]{0x0000000000010810L});
    public static final BitSet FOLLOW_exp_base_in_exp_mult200 = new BitSet(new long[]{0x0000000000040042L});
    public static final BitSet FOLLOW_NUMERO_in_exp_base234 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ABRIRPARENTESIS_in_exp_base242 = new BitSet(new long[]{0x0000000000010810L});
    public static final BitSet FOLLOW_expr_in_exp_base246 = new BitSet(new long[]{0x0000000000000100L});
    public static final BitSet FOLLOW_CERRARPARENTESIS_in_exp_base248 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_exp_base260 = new BitSet(new long[]{0x0000000000000002L});

}